package ru.amse.tsyganov.jumleditor.view;

import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

import ru.amse.tsyganov.jumleditor.commands.Command;

public abstract class ActivePoint {
	private Cursor cursor;
	
	private int temporaryActivePointX;
	private int temporaryActivePointY;
	
	private final int activePointWidth = 6;
	private final int activePointHeight = 6;
	
	public abstract int getCurrentActivePointX();
	public abstract int getCurrentActivePointY();
	public abstract Command perform();
	public abstract void paintTempResult(GC gc);
	public abstract Cursor createCursor();
	
	public void paintActivePoint(GC gc) {
		gc.setForeground(Colors.blackColor);
		gc.setBackground(Colors.whiteColor);
		gc.fillRectangle(getRectangle());
		gc.drawRectangle(getRectangle());
	}

	public final Rectangle getRectangle() {
		return new Rectangle(
				getCurrentActivePointX() - getActivePointWidth() / 2, 
				getCurrentActivePointY() - getActivePointHeight() / 2, 
				getActivePointWidth(), getActivePointHeight());
	}
	
	public final void move(int x, int y) {
		temporaryActivePointX = x;
		temporaryActivePointY = y;
	}
	public final Cursor getCursor() {
		if (cursor == null) {
			cursor = createCursor();
		}
		return cursor;
	}
	public final int getActivePointHeight() {
		return activePointHeight;
	}
	public final int getActivePointWidth() {
		return activePointWidth;
	}
	
	public int getTemporaryActivePointX() {
		return temporaryActivePointX;
	}
	public int getTemporaryActivePointY() {
		return temporaryActivePointY;
	}
	
}
